-- created by kumiler
-- on 2023/1/6 15:20
-- DESC

insert overwrite table spmi_dim.dim_spmi_pcp_center_cost_mt partition (mt)
select id,
       waybill_month,
       send_financial_center_name,
       send_financial_center_code,
       financial_center_name,
       financial_center_code,
       ticket_price,
       project_code,
       property,
       create_time,
       substring (waybill_month,1,7) as mt
from (
         select *, rank() over (partition by waybill_month order by to_date(create_time) desc) as time_rank
         from spmi_ods.spmi_pcp_center_cost
         where dt = '{{ execution_date | cst_ds }}'
     ) t
where time_rank = 1
;